﻿var processid = $('#processid').val();
var activityid = $('#activityid').val();
$(document).ready(function () {
    definitions();
});

function initialProcess(p) {
    setFieldsData(p.fields);
    setConditionData(p.conditions);
    setContainerData(p.queues);
    $('.ws-fields').sortable();
    $('.ws-queues').sortable();
    $('.ws-containers').sortable();
}

function definitions() {
    var $fieldli = $('<li class="dc-field unsave" style="float:left;"><div class="text-display" style="line-height:20px;text-align:center;"></div></li>');
    $.registerListItem('ws-fields', $fieldli);
    $.registerListItem('ws-conditions', $('<li class="unsave" style="float:left;" saved="false"><div class="display-text" style="line-height:20px;text-align:center;"></div></li>'));
    $.registerListItem('ws-queues', $('<li class="ws-queueitem unsave"><div ><ul class="ws-containers"></ul></div></li>'));
    $.registerListItem('ws-containers', $('<li class="ws-containeritem unsave"><ul class="ws-activities"></ul></li>'));
    $.registerListItem('ws-activities', $('<li class="unsave"><div class="display-text"></div></li>'));
    $.registerListItem('pre-form', $('<li class="preview-field"></li>'));

}
function onConditionNodeDropped(e) {
    if ($(e.destinationItem).attr('elementtype') == 'condition-single') {
        e.preventDefault();
        alert("单条件不能添加子项，请用或运算或者并运算代替");
    }
}

function getTreeviewSelectedItemText($treeview, e) {
    var tv = $treeview.data('tTreeView');
    var nodetext = tv.getItemText(e.item);
    return nodetext;
}

function getProcessData() {
    var fs = getFieldsData();
    var cs = getCondtionsData();
    var qs = getCondtainersData();
    var p = { Fields: fs, Conditions: cs, Queues: qs, ID: processid };
    p = JSON.stringify(p);
    return p;
}
function savedata() {
    $('.dc_process_save').click(function () {
        p = getProcessData();

        $.ajax({
            url: "/ProcessRoll/SaveProcess",
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: p,
            success: function (result) {
            }
        });
    });
}

function setDetailToWindowEditor($target, intial, $w) {
    var $screen = $(document);
    $w.css('left', $screen.width() / 2 - $w.width() / 2).css('top', '150px');
    $w.data('tWindow').content(intial).title('表单编辑框').open();
}



